package com.jy.api.dao;

import com.jy.api.domain.DiscountPromotionProduct;
import com.jy.api.domain.PromotionType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

public interface DiscountPromotionProductDao  extends JpaRepository<DiscountPromotionProduct, Integer>, JpaSpecificationExecutor<DiscountPromotionProduct> {

    Page<DiscountPromotionProduct> findAllByPromotionId(int promotionId, Pageable pageable);


    @Modifying
    @Transactional
    @Query(value = "update `discount_promotion_product` SET  `promotion_type` =:promotionType  where `promotion_id`=:promotionId " ,nativeQuery = true)
    void updateUnfinishedOrder(@Param("promotionType") int promotionType, @Param("promotionId")int promotionId);

    DiscountPromotionProduct findByProductIdAndPromotionType(String productId,PromotionType promotionType);


    DiscountPromotionProduct findByProductIdAndPromotionId(String productId,int promotionId);



}
